import java.math.BigInteger;


public class Cond implements Node{

	public String token = "<cond>";
	public Node comp = null;
	public Node cond = null;
	public Node cond2 = null;
	private boolean not = false;
			
	public Cond(){
		int token = PSTree.Core_TK.getToken();
		// first token should be '('or ! or [
		// if token is ( go to comp
		// if token is ! go to cond
		// if token is [ there must be 2 conds
		if(token == 20){
			PSTree.Core_TK.skipToken(); // skip (
			this.comp = new Comp();
			// token should be )
			token = PSTree.Core_TK.getToken();
			if (token != 21){
				System.out.println("Error: missing \")\" in Cond");
				System.exit(1);
			}
			PSTree.Core_TK.skipToken(); // skip )
		}
		else if (token == 15){
			PSTree.Core_TK.skipToken(); // skip !
			this.cond =  new Cond();
			
		}
		else if(token == 16){
			 PSTree.Core_TK.skipToken(); // skip [
			// if [ you have at least two conds
			this.cond = new Cond();
			token = PSTree.Core_TK.getToken();
			// token sould be && or ||
			if(token != 18 || token != 19){
				System.out.println("Error: missing \"&&\" or \"||\" in Cond");
				System.exit(1);
			}
			// parse second condition
			this.cond2 = new Cond();
			// token should be ]
			token = PSTree.Core_TK.getToken();
			if (token != 17){
				System.out.println("Error: missing \"]\" in Cond");
				System.exit(1);
			}
		}
		else{
			System.out.println("Error: unexpected token after \"if\" in Cond");
			System.exit(1);
		}
	}

	@Override
	public void print(int indent) {
		System.out.print("( ");
		if(this.comp != null){
			this.comp.print(indent+1);
		}
		if(this.cond != null){
			this.cond.print(indent+1);
		}
		if(this.cond2 != null){
			this.cond2.print(indent+1);
		}
		if(this.not){
			System.out.print("!");
		}
		System.out.print(" ) ");
		
	}

	
	public void execute() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public BigInteger intexecute() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean compexecute() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String Stringexcec() {
		// TODO Auto-generated method stub
		return null;
	}
	
}
